import axios from 'axios'
import Cookie from 'js-cookie'
axios.defaults.withCredentials = true
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
axios.defaults.headers['token'] = Cookie.get('auth') || ''
axios.defaults.headers.post['Content-Type'] = 'application/json'
let request = axios.create({
  baseURL: 'http://backend-api-01.newbee.ltd/api/v1'
})

// 新增地址接口
export const addAddress = (params) => {
  return request({
    method: 'POSt',
    url: '/address',
    params: params
  })
}
// 编辑地址接口
export const EditAddress = (params) => {
  return request({
    method: 'PUT',
    url: '/address',
    params: params
  })
}
// export const EditAddress = function (params) {
//   return axios.put('http://backend-api-01.newbee.ltd/api/v1/address', params)
// }
// 删除地址接口
export const DeleteAddress = (id) => {
  return request({
    method: 'delete',
    url: `/address/${id}`
  })
}
// 地址列表更新请求
export const getAddressList = () => {
  return request({
    method: 'get',
    url: '/address',
    params: {
      pageNumber: 1,
      pageSize: 1000
    }
  })
}
// 首页资源请求
export const getHome = () => {
  return request({
    method: 'get',
    url: '/index-infos'
  })
}
// 加入购物车请求
export const addCart = (params) => {
  return request({
    method: 'POST',
    url: '/shop-cart',
    params: params
  })
}

// 购物车页面数据请求
export const getCart = (params) => {
  return request({
    method: 'get',
    url: '/shop-cart',
    params: params
  })
}

// 详情页数据请求
export const getDetail = (id) => {
  return request({
    method: 'get',
    url: `/goods/detail/${id}`
  })
}
export default request
// 一个接口文件只能导出一个defaul
